.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group.  In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document.  The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
.\" Copyright (c) 2009, Sun Microsystems, Inc.  All Rights Reserved.
.\" Copyright (c) 2014, Joyent, Inc.
.\" Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
.\"
.TH UTIMES 2 "November 8, 2020"
.SH NAME
utimes, lutimes, futimes, futimesat, futimens, utimensat \- set file access and modification times
.SH SYNOPSIS
.nf
#include <sys/time.h>

\fBint\fR \fButimes\fR(\fBconst char *\fR\fIpath\fR, \fBconst struct timeval\fR \fItimes\fR[2]);
.fi

.LP
.nf
\fBint\fR \fBlutimes\fR(\fBconst char *\fR\fIpath\fR, \fBconst struct timeval\fR \fItimes\fR[2]);
.fi

.LP
.nf
\fBint\fR \fBfutimes\fR(\fBint\fR \fIfildes\fR, \fBconst struct timeval\fR \fItimes\fR[2]);
.fi

.LP
.nf
\fBint\fR \fBfutimesat\fR(\fBint\fR \fIfildes\fR, \fBconst char *\fR\fIpath\fR,
     \fBconst struct timeval\fR \fItimes\fR[2]);
.fi

.LP
.nf
#include <sys/stat.h>

\fBint\fR \fBfutimens\fR(\fBint\fR \fIfildes\fR, \fBconst timespec_t\fR \fInstimes[2]\fR);

\fBint\fR \fButimensat\fR(\fBint\fR \fIfildes\fR, \fBconst char *\fR\fIpath\fR,
    \fBconst timespec_t\fR \fInstimes[2]\fR, \fBint\fR \fIflag\fR);

.SH DESCRIPTION
The \fButimes()\fR function sets the access and modification times of the file
pointed to by the \fIpath\fR argument to the value of the \fItimes\fR argument.
It allows time specifications accurate to the microsecond.
.sp
.LP
The \fBlutimes()\fR function operates like \fButimes()\fR except if \fIpath\fR
points to a symbolic link; in that case \fBlutimes()\fR changes the access and
modifications times of the link, while \fButimes()\fR changes the file that
is referenced by the link.
.sp
.LP
The \fBfutimes()\fR function sets the access and modification times of the
file referenced by the file descriptor \fIfildes\fR.
.sp
.LP
The \fBfutimesat()\fR function also sets access and modification times.  See
\fBfsattr\fR(7). If \fIpath\fR is a relative path name, however,
\fBfutimesat()\fR resolves the path relative to the \fIfildes\fR argument
rather than the current working directory.  If \fIfildes\fR is set to
\fBAT_FDCWD\fR, defined in <\fBfcntl.h\fR>, \fBfutimesat()\fR resolves the path
relative to the current working directory.  If \fIpath\fR is a null pointer,
\fBfutimesat()\fR sets the access and modification times on the file referenced
by \fIfildes\fR. The \fIfildes\fR argument is ignored if
\fBfutimesat()\fR is provided with an absolute path.
.sp
.LP
The \fItimes\fR argument is an array of \fBtimeval\fR structures. The first
array member represents the date and time of last access, and the second member
represents the date and time of last modification.  The times in the
\fBtimeval\fR structure are measured in seconds and microseconds since the
Epoch, although rounding toward the nearest second may occur.
.sp
.LP
If the \fItimes\fR argument is a null pointer, the access and modification
times of the file are set to the current time.  The effective user \fBID\fR of
the process must be the same as the owner of the file, or must have write
access to the file or the {\fBPRIV_FILE_OWNER\fR} privilege to use this call in
this manner. Upon completion, \fButimes()\fR will mark the time of the last
file status change, \fBst_ctime\fR, for update.
.sp
.LP
The \fBfutimens()\fR and \fButimensat()\fR functions also set access and
modification times; however, instead of taking \fBstruct timeval\fR, they take
\fBtimespec_t\fR which allows for nanosecond granularity. The \fBfutimens()\fR
function sets the access and modification times on the file descriptor
referenced by \fIfildes\fR.
.sp
.LP
The \fButimensat()\fR function determines the file to set the access and
modification times in an similar way to \fBfutimesat()\fR. If the argument
\fIpath\fR is an absolute path, then the argument \fIfildes\fR is ignored;
otherwise, \fIpath\fR is interpreted as a path relative to the directory
specified by \fIfildes\fR. If \fIfildes\fR is set to \fBAT_FDCWD\fR, then
\fIpath\fR is resolved relative to the current working directory. The behavior
when encountering symbolic links may be controlled by the value of the
\fIflag\fR argument. If the value of flag is the constant
\fBAT_SYMLINK_NOFOLLOW\fR, then when a symbolic link is encountered while
resolving a path, it will not be followed. Otherwise, the value of \fIflag\fR
should be \fB0\fR. Note that, unlike \fBfutimesat()\fR, \fButimensat()\fR
does not accept a null pointer for the \fIpath\fR argument.
.SH RETURN VALUES
Upon successful completion, \fB0\fR is returned.  Otherwise, \fB\(mi1\fR is
returned, \fBerrno\fR is set to indicate the error, and the file times will not
be affected.
.SH ERRORS
The \fButimes()\fR, \fBlutimes()\fR, \fBfutimes()\fR, \fBfutimesat()\fR,
\fBfutimens()\fR, and \fButimensat()\fR
functions will fail if:
.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 16n
Search permission is denied by a component of the path prefix; or the
\fItimes\fR argument is a null pointer and the effective user \fBID\fR of the
process does not match the owner of the file and write access is denied.
.RE

.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 16n
The \fIpath\fR or \fItimes\fR argument points to an illegal address.
.RE

.sp
.ne 2
.na
\fB\fBEINTR\fR\fR
.ad
.RS 16n
A signal was caught during the execution of the \fButimes()\fR,
\fBlutimes()\fR, \fBfutimes()\fR,
\fBfutimesat()\fR, \fBfutimens()\fR, or \fButimensat()\fR functions.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 16n
The number of microseconds specified in one or both of the \fBtimeval\fR
structures pointed to by \fItimes\fR was greater than or equal to 1,000,000 or
less than 0. The number of nanoseconds specified in one or both of the
\fBtimespec_t\fR structures pointed to by \fInstimes\fR was greater than or
equal to 1,000,000,000 or less than 0.
.RE

.sp
.ne 2
.na
\fB\fBEIO\fR\fR
.ad
.RS 16n
An I/O error occurred while reading from or writing to the file system.
.RE

.sp
.ne 2
.na
\fB\fBELOOP\fR\fR
.ad
.RS 16n
Too many symbolic links were encountered in resolving \fIpath\fR.
.RE

.sp
.ne 2
.na
\fB\fBENAMETOOLONG\fR\fR
.ad
.RS 16n
The length of the \fIpath\fR argument exceeds {\fIPATH_MAX\fR} or a pathname
component is longer than {\fINAME_MAX\fR}.
.RE

.sp
.ne 2
.na
\fB\fBENOLINK\fR\fR
.ad
.RS 16n
The \fIpath\fR argument points to a remote machine and the link to that machine
is no longer active.
.RE

.sp
.ne 2
.na
\fB\fBENOENT\fR\fR
.ad
.RS 16n
A component of \fIpath\fR does not name an existing file or \fIpath\fR is an
empty string.
.RE

.sp
.ne 2
.na
\fB\fBENOTDIR\fR\fR
.ad
.RS 16n
A component of the path prefix is not a directory or the \fIpath\fR argument is
relative and the \fIfildes\fR argument is not \fBAT_FDCWD\fR or does not refer
to a valid directory.
.RE

.sp
.ne 2
.na
\fB\fBEPERM\fR\fR
.ad
.RS 16n
The \fItimes\fR argument is not a null pointer and the calling process's
effective user \fBID\fR has write access to the file but does not match the
owner of the file and the calling process does not have the appropriate
privileges.
.RE

.sp
.ne 2
.na
\fB\fBEROFS\fR\fR
.ad
.RS 16n
The file system containing the file is read-only.
.RE

.sp
.LP
The \fButimes()\fR, \fBfutimesat()\fR, and \fButimensat()\fR functions may fail
if:
.sp
.ne 2
.na
\fB\fBENAMETOOLONG\fR\fR
.ad
.RS 16n
Path name resolution of a symbolic link produced an intermediate result whose
length exceeds {\fIPATH_MAX\fR}.
.RE

.SH ATTRIBUTES
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Committed
_
Standard	See below.
.TE

.sp
.LP
For \fButimes()\fR, \fButimensat()\fR and \fBfutimensat()\fR, see \fBstandards\fR(7).
.SH SEE ALSO
.BR stat (2),
.BR utime (2),
.BR attributes (7),
.BR fsattr (7),
.BR standards (7)
